#pragma once
#include <stdio.h>
#include <string>
#include <future>
#include "wf_task/frpc_client.h"
#include "win_pb/frpc.pb.h"

namespace frpcType
{

using GetUserInfoDone = ::std::function<void (UserInfo *, ::frpc::Context *)>;

class UserServiceClient : public ::frpc::Client
{
public:
	void GetUserInfo(const DefaultArg *req, GetUserInfoDone done);
	std::pair<UserInfo, ::frpc::Context> GetUserInfo(const DefaultArg *req);


	UserServiceClient(const char *host, unsigned short port);

};

inline UserServiceClient::UserServiceClient(const char *host, unsigned short port):
	::frpc::Client("UserService")
{
	struct ::frpc::RPCClientParams params = frpc::RPC_CLIENT_PARAMS_DEFAULT;
	
	params.host = host;
	params.port = port;
	this->frpc::Client::init(&params);
}


inline void UserServiceClient::GetUserInfo(const DefaultArg *req, GetUserInfoDone done)
{
	auto *task = this->create_rpc_client_task(std::string("GetUserInfo"), ::std::move(done));

	task->get_req()->serialize(req);
	task->start();
}
inline std::pair<UserInfo, ::frpc::Context> UserServiceClient::GetUserInfo(const DefaultArg* req)
{
	std::pair<UserInfo, ::frpc::Context> v ;
	std::promise<void> p;
	GetUserInfoDone done = [&p,&v](UserInfo* rep, ::frpc::Context* ctx) {
		std::swap(*rep,v.first);
		std::swap(*ctx, v.second);
		p.set_value();
	};
	this->GetUserInfo(req, ::std::move(done));
	p.get_future().get();
	return v;
}

using GetExchangeListDone = ::std::function<void (ExchangeArray *, ::frpc::Context *)>;
using GetCollectionListDone = ::std::function<void (CollectionArray *, ::frpc::Context *)>;
using GetCollectionContentDone = ::std::function<void (ContractArray *, ::frpc::Context *)>;
using GetBarSeriesDone = ::std::function<void (DefaultArg *, ::frpc::Context *)>;
using GetBarRangeDone = ::std::function<void (DefaultArg *, ::frpc::Context *)>;
using UpdateBarSeriesDone = ::std::function<void (DefaultArg *, ::frpc::Context *)>;

class StaticDataServiceClient : public ::frpc::Client
{
public:
	void GetExchangeList(const DefaultArg *req, GetExchangeListDone done);
	std::pair<ExchangeArray, ::frpc::Context> GetExchangeList(const DefaultArg *req);

	void GetCollectionList(const DefaultArg *req, GetCollectionListDone done);
	std::pair<CollectionArray, ::frpc::Context> GetCollectionList(const DefaultArg *req);

	void GetCollectionContent(const DefaultArg *req, GetCollectionContentDone done);
	std::pair<ContractArray, ::frpc::Context> GetCollectionContent(const DefaultArg *req);

	void GetBarSeries(const GetBarRequest *req, GetBarSeriesDone done);
	std::pair<DefaultArg, ::frpc::Context> GetBarSeries(const GetBarRequest *req);

	void GetBarRange(const GetBarRequest *req, GetBarRangeDone done);
	std::pair<DefaultArg, ::frpc::Context> GetBarRange(const GetBarRequest *req);

	void UpdateBarSeries(const UpdateBarRequest *req, UpdateBarSeriesDone done);
	std::pair<DefaultArg, ::frpc::Context> UpdateBarSeries(const UpdateBarRequest *req);


	StaticDataServiceClient(const char *host, unsigned short port);

};

inline StaticDataServiceClient::StaticDataServiceClient(const char *host, unsigned short port):
	::frpc::Client("StaticDataService")
{
	struct ::frpc::RPCClientParams params = frpc::RPC_CLIENT_PARAMS_DEFAULT;
	
	params.host = host;
	params.port = port;
	this->frpc::Client::init(&params);
}


inline void StaticDataServiceClient::GetExchangeList(const DefaultArg *req, GetExchangeListDone done)
{
	auto *task = this->create_rpc_client_task(std::string("GetExchangeList"), ::std::move(done));

	task->get_req()->serialize(req);
	task->start();
}
inline std::pair<ExchangeArray, ::frpc::Context> StaticDataServiceClient::GetExchangeList(const DefaultArg* req)
{
	std::pair<ExchangeArray, ::frpc::Context> v ;
	std::promise<void> p;
	GetExchangeListDone done = [&p,&v](ExchangeArray* rep, ::frpc::Context* ctx) {
		std::swap(*rep,v.first);
		std::swap(*ctx, v.second);
		p.set_value();
	};
	this->GetExchangeList(req, ::std::move(done));
	p.get_future().get();
	return v;
}

inline void StaticDataServiceClient::GetCollectionList(const DefaultArg *req, GetCollectionListDone done)
{
	auto *task = this->create_rpc_client_task(std::string("GetCollectionList"), ::std::move(done));

	task->get_req()->serialize(req);
	task->start();
}
inline std::pair<CollectionArray, ::frpc::Context> StaticDataServiceClient::GetCollectionList(const DefaultArg* req)
{
	std::pair<CollectionArray, ::frpc::Context> v ;
	std::promise<void> p;
	GetCollectionListDone done = [&p,&v](CollectionArray* rep, ::frpc::Context* ctx) {
		std::swap(*rep,v.first);
		std::swap(*ctx, v.second);
		p.set_value();
	};
	this->GetCollectionList(req, ::std::move(done));
	p.get_future().get();
	return v;
}

inline void StaticDataServiceClient::GetCollectionContent(const DefaultArg *req, GetCollectionContentDone done)
{
	auto *task = this->create_rpc_client_task(std::string("GetCollectionContent"), ::std::move(done));

	task->get_req()->serialize(req);
	task->start();
}
inline std::pair<ContractArray, ::frpc::Context> StaticDataServiceClient::GetCollectionContent(const DefaultArg* req)
{
	std::pair<ContractArray, ::frpc::Context> v ;
	std::promise<void> p;
	GetCollectionContentDone done = [&p,&v](ContractArray* rep, ::frpc::Context* ctx) {
		std::swap(*rep,v.first);
		std::swap(*ctx, v.second);
		p.set_value();
	};
	this->GetCollectionContent(req, ::std::move(done));
	p.get_future().get();
	return v;
}

inline void StaticDataServiceClient::GetBarSeries(const GetBarRequest *req, GetBarSeriesDone done)
{
	auto *task = this->create_rpc_client_task(std::string("GetBarSeries"), ::std::move(done));

	task->get_req()->serialize(req);
	task->start();
}
inline std::pair<DefaultArg, ::frpc::Context> StaticDataServiceClient::GetBarSeries(const GetBarRequest* req)
{
	std::pair<DefaultArg, ::frpc::Context> v ;
	std::promise<void> p;
	GetBarSeriesDone done = [&p,&v](DefaultArg* rep, ::frpc::Context* ctx) {
		std::swap(*rep,v.first);
		std::swap(*ctx, v.second);
		p.set_value();
	};
	this->GetBarSeries(req, ::std::move(done));
	p.get_future().get();
	return v;
}

inline void StaticDataServiceClient::GetBarRange(const GetBarRequest *req, GetBarRangeDone done)
{
	auto *task = this->create_rpc_client_task(std::string("GetBarRange"), ::std::move(done));

	task->get_req()->serialize(req);
	task->start();
}
inline std::pair<DefaultArg, ::frpc::Context> StaticDataServiceClient::GetBarRange(const GetBarRequest* req)
{
	std::pair<DefaultArg, ::frpc::Context> v ;
	std::promise<void> p;
	GetBarRangeDone done = [&p,&v](DefaultArg* rep, ::frpc::Context* ctx) {
		std::swap(*rep,v.first);
		std::swap(*ctx, v.second);
		p.set_value();
	};
	this->GetBarRange(req, ::std::move(done));
	p.get_future().get();
	return v;
}

inline void StaticDataServiceClient::UpdateBarSeries(const UpdateBarRequest *req, UpdateBarSeriesDone done)
{
	auto *task = this->create_rpc_client_task(std::string("UpdateBarSeries"), ::std::move(done));

	task->get_req()->serialize(req);
	task->start();
}
inline std::pair<DefaultArg, ::frpc::Context> StaticDataServiceClient::UpdateBarSeries(const UpdateBarRequest* req)
{
	std::pair<DefaultArg, ::frpc::Context> v ;
	std::promise<void> p;
	UpdateBarSeriesDone done = [&p,&v](DefaultArg* rep, ::frpc::Context* ctx) {
		std::swap(*rep,v.first);
		std::swap(*ctx, v.second);
		p.set_value();
	};
	this->UpdateBarSeries(req, ::std::move(done));
	p.get_future().get();
	return v;
}
} // end namespace frpcType

